<?php
    include_once("db_connect.php");
    $postdata = file_get_contents("php://input");
    if(isset($postdata) && !empty($postdata)){
        $request = json_decode($postdata);
        $username = mysqli_real_escape_string($mysqli, trim($request->username));
        $password = mysqli_real_escape_string($mysqli, trim($request->password));

        $sql = "SELECT * FROM login_user WHERE username= '$username' AND password = '$password'";
        $result = mysqli_query($mysqli, $sql);
        while($row = mysqli_fetch_array($result)){
            if($row["accesstoken"] == 1){
                $nums = mysqli_num_rows($result);
                if($nums > 0){
                    $data=array('message' => 'Login Admin Success','username' => $username);
                    echo json_encode($data);
                }else{
                    $data=array('message'=> 'Login Falied');
                    echo json_encode($data);
                }
            }
            if($row["accesstoken"] != 1){
                $nums = mysqli_num_rows($result);
                if($nums > 0){
                    $data=array('message' => 'Login User Success','username' => $username);
                    echo json_encode($data);
                }else{
                    $data=array('message'=> 'Login Falied');
                    echo json_encode($data);
                }
            }
        }
    }
?>